<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品管理</title> <#include "/WEB-INF/content/module-index.html">
<script type="text/javascript">
var typeTree=[
		{"id":"","text":"空","children":[]},
<#list map.typeTree as item>
   	<#if item_has_next>
   		{"id":"${item.id}","text":"${item.text}",
"children":[
<#list item.children as ite>
	<#if ite_has_next>
 		{"id":"${ite.id}","text":"${ite.text}"},  			
	<#else>
		{"id":"${ite.id}","text":"${ite.text}"}
	</#if>
</#list>
]},
   	<#else>
   		{"id":"${item.id}","text":"${item.text}",
   		"children":[
   		<#list item.children as ite>
   			<#if ite_has_next>
   		 		{"id":"${ite.id}","text":"${ite.text}"},  			
   			<#else>
   				{"id":"${ite.id}","text":"${ite.text}"}
   			</#if>
   		</#list>
   		]}
   	</#if>
</#list>
];
$(function(){
	$("#search").click(function(){
		var productname=$("#productname").val();
		var orderStatus=$("#status").val();
		var mobile=$("#mobile").val();
		var terminal=$("#terminal").val();
		var spid=$("#spid").val();
		var ptid=$("#ptid").combobox("getValue");
		var leftCreateTime=$("#leftCreateTime").datetimebox("getValue");
		var rightCreateTime=$("#rightCreateTime").datetimebox("getValue");
		var leftPayTime=$("#leftPayTime").datetimebox("getValue");
		var rightPayTime=$("#rightPayTime").datetimebox("getValue");
		$("#grid").datagrid("reload",{"productname":productname,"spid":spid,"orderStatus":orderStatus,"ptid":ptid,"_mobile":mobile,
		"terminal":terminal,"leftCreateTime":leftCreateTime,"rightCreateTime":rightCreateTime,"leftPayTime":leftPayTime,"rightPayTime":rightPayTime});		
	});	
  	$("#parent").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
  		data:typeTree,
  		onChange:function(data){
  			$("#ptid").combobox('setValue','');
  			for(var i in typeTree){
  				if(typeTree[i].id==data){
  					$("#ptid").combobox('loadData',typeTree[i].children);
  				}
  			}
  		}
  	});	
	$("#ptid").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
	});
});
function productFormatter(value,rowData,rowIndex){
	if(value==-1){
		return "未知";
	}else
		if(value==0){
			return "票劵";
		}else
			if(value==1){
				return "微信支付";
			}else
				if(value==2){
					return "会员卡支付";
				}else
					if(value==3){
						return "支付宝支付";
					}else
						if(value==4){
							return "银联支付";
						}else
							if(value==5){
								return "道乐支付";
							}
}
function comFormatter(value,rowData,rowIndex){
	if(value=="0"){
		return "是";
	}else
		if(value=="1"){
			return "否";
		}else{
			return "未设置";
		}
}

function typeFormatter(value,rowData,rowIndex){
	if(value==0){
		return "商品交易";
	}else
		if(value==1){
			return "会员卡充值";
		}else
			if(value==2){
				return "道乐充值";
			}else
				if(value==3){
					return "商品配送交易";
				}else
					if(value==4){
						return "票券交易";
					}
}

function statusFormatter(value,rowData,rowIndex){
	if(value==0){
		return "待付款";
	}else
		if(value==1){
			return "待收货";
		}else
			if(value==2){
				return "完成";
			}else
				if(value==3){
					return "退款/货关闭";
				}else
					if(value==4){
						return "订单关闭";
					}else
						return "未知";
}

function refundFormatter(value,rowData,rowIndex){
	if(rowData.status==1){
		var html = "";
		if((rowData.paytype==1)||(rowData.paytype==3)||(rowData.paytype==5)){
			html += "<a href='javascript:refund(\""+rowData.oid+"\")'>退款/货</a>&nbsp;&nbsp;&nbsp;";
		}
		html += "<a href='javascript:send(\""+rowData.oid+"\")'>发货</a>";
		return html;
	}
}

function refund(oid){
	top.openModule("order_info-refund","订单退款/退货","order/refund/new?_id="+oid);
}

function send(oid){
	top.openModule("order_info-send","订单发货","order/send/"+oid+"/edit");
}

function downloads(){
	var productname=$("#productname").val();
	var orderStatus=$("#status").val();
	var mobile=$("#mobile").val();
	var terminal=$("#terminal").val();
	var spid=$("#spid").val();
	var ptid=$("#ptid").combobox("getValue");
	var leftCreateTime=$("#leftCreateTime").datetimebox("getValue");
	var rightCreateTime=$("#rightCreateTime").datetimebox("getValue");
	var leftPayTime=$("#leftPayTime").datetimebox("getValue");
	var rightPayTime=$("#rightPayTime").datetimebox("getValue");
	var params="?productname="+productname+"&spid="+spid+"&orderStatus="+orderStatus+"&ptid="+
	ptid+"&_mobile="+mobile+"&terminal="+terminal+"&leftCreateTime="+leftCreateTime+
	"&rightCreateTime="+rightCreateTime+"&leftPayTime="+leftPayTime+"&rightPayTime="+rightPayTime;
	window.location.href=moduleUrl.substring(0,moduleUrl.lastIndexOf("/"))+"/download"+params;
}

</script>
<style>
a.btn-border{
	border: 1px solid #ccc;
}
</style>
</head>
<body>
<body class="easyui-layout">
	<div region="center" style="padding: 5px; background:#eee;">
		<div id="toolbar">
			<input id="spid" placeholder="订单编号"/>
			订单状态:<select id="status">
				<option value="">空</option>
			   <option value="0">待付款</option>
               <option value="1">待收货</option>
               <option value="2">已完成</option>
               <option value="3">退款/货关闭</option>
               <option value="4">订单关闭</option>
			</select>
			<input id="productname" placeholder="商品名称"/>
			<input id="mobile" placeholder="手机号码"/>
			<!-- <input id="terminal" placeholder="终端"/> -->
			商品分类:<input id="parent" placeholder="商品分类">
			<input id="ptid" placeholder="商品分类"/>
			创建时间:<input id="leftCreateTime" class="easyui-datetimebox"/>至:<input id="rightCreateTime" class="easyui-datetimebox"/>
			支付时间:<input id="leftPayTime" class="easyui-datetimebox"/>至:<input id="rightPayTime" class="easyui-datetimebox"/>
			<a id="search" class="easyui-linkbutton" icon="icon-search" style="border: 1px solid #ccc" plain="true">搜索</a>
			<br/><a class="easyui-linkbutton" onclick="javascript:downloads();" icon="icon-add" style="border: 1px solid #ccc" plain="true">导出</a>			
		</div>
		<table id="grid" class="easyui-datagrid" url="query" align="center" idField="oid" rownumbers="true" striped="true" fitColumns="true" fit="true" pagination="true" singleSelect="true" toolbar="#toolbar">
			<thead>
				<tr>
					<th field="oid" width="10">订单编号</th>
					<th field="uid" width="10">用户手机号码</th>
					<th field="pid" width="10">商品销售名称</th>
					<th field="totalprice" width="5">订单价格</th>
					<th field="amount" width="5">商品数量</th>
					<th field="ordertype" width="5" formatter="typeFormatter">业务类型</th>
					<th field="paytype" width="5" formatter="productFormatter">支付类型</th>
					<th field="tradeNo" width="10">交易流水号</th>
					<th field="payTime" width="10">支付时间</th>
					<th field="status" width="5" formatter="statusFormatter">状态</th>
					<th field="linkman" width="5">收货人</th>
					<th field="mobile" width="5">电话</th>
					<th field="addr" width="20">收货地址</th>
					<th field="createtime" width="10" align='center'>创建时间</th>
					<@auth code="order:refund:create">
					<th field="handler" width="8" formatter="refundFormatter">操作</th>
					</@auth>
				</tr>
			</thead>
		</table>
	</div>
</body>
</body>

</html>